import csv
import main_activity.writefile

def load_file(file_name):
    value = []

    with open(file_name, 'r', encoding='utf-8') as f:
        f_csv = csv.reader(f)
        for row in f_csv:
            value.append(row)
        return value


def main(name):
    global temp
    csv_path = "data\\" + name + ".csv"
    value = load_file(csv_path)
    print("请输入需要查询的人的姓名或学号： 输入e退出")
    a = input()
    if a=="e":
        return 0
    print("正在查询。。。。。")
    print()
    if a.isdigit():
        for i in range(len(value)):
            if value[i][4] == a:
                print(value[i])
                temp = i
                break

            if i == len(value) - 1:
                print("未找到相关信息")
    else:
        for i in range(len(value)):
            if value[i][0] == a:
                print(value[i])
                temp = i
                break
            if i == len(value) - 1:
                print("未找到相关信息")

    print()
    print("需要修改的值")
    print("1、性别 2、学院 3、年级 4、学号 5、电话  6、时长 7、活动项目 8、退出")
    print("输入对应的编号")
    j = input()
    if j.isdigit() and 1 <= int(j) <= 7:
        print("原数据为" + value[temp][int(j)])
        print("请输入新的值")
        value[temp][int(j)] = input()
        main_activity.writefile.main(csv_path,value)
        print("数据已修改为" + value[temp][int(j)])
    elif j == "8":
        return 0
    else:
        print("请输入对应的编号！")
